<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康19</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>日志<small>访问日志</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>日志管理</el-breadcrumb-item>
                    <el-breadcrumb-item>访问日志</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="操作人/IP/资源" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="code" label="操作人" align="center"></el-table-column>
                        <el-table-column prop="name" label="操作时间" align="center"></el-table-column>
                        <el-table-column prop="name" label="IP地址" align="center"></el-table-column>
                        <el-table-column prop="helpCode" label="访问资源" align="center"></el-table-column>
                        <el-table-column prop="remark" label="时常" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>

                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:3,
                    total:100,
                    queryString:null,
                },
                dataList: [],//列表数据
                formData: {},//表单数据
                tableData:[],//新增和编辑表单中对应的检查项列表数据
                checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false,
                rules: {//校验规则
                    code: [{ required: true, message: '项目编码为必填项', trigger: 'blur' }],
                    name: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }]
                }//控制编辑窗口显示/隐藏
            },
            created() {
                this.findPage();
            },
            methods: {
                //编辑
                handleEdit() {
                    axios.post("/checkgroup/edit.do?checkitemIds="+this.checkitemIds,this.formData).then((res)=>{
                        if(res.data.flag){
                            this.checkitemIds=res.data.data;
                            this.dialogFormVisible4Edit=false;
                            this.$message.success(res.data.message)
                            this.findPage();
                        }else {
                            this.dialogFormVisible4Edit=false;
                            this.$message.error(res.data.message)
                        }

                    })
                },
                //添加
                handleAdd () {
                            /*发送异步请求*/
                    axios.post("/checkgroup/add.do?checkitemIds="+this.checkitemIds,this.formData).then((res)=>{
                        /*判断后端响应信息*/
                        if(res.data.flag){
                            this.dialogFormVisible=false;
                            this.$message.success(res.data.message);
                            this.findPage();
                        }else {
                            this.$message.error(res.data.message);
                        }
                    })
                },
                //分页查询
                findPage() {

                    var parma={
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                    }
                    axios.post("/checkgroup/findPage.do",parma).then((res)=>{
                        this.dataList=res.data.rows;
                        this.total=this.pagination.total;
                    })
                },
                // 重置表单
                resetForm(code) {
                    this.formData={};
                    /*this.$refs['dataAddForm'].validate();*/
                },
                // 弹出添加窗口
                handleCreate() {

                    this.dialogFormVisible=true;
                    /*重置表单*/
                    this.resetForm();
                    this.activeName="first";
                    this.checkitemIds=[];

                    axios.post("/checkitem/findAll.do").then((res)=>{
                       this.tableData=res.data.data;
                    })
                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    this.dialogFormVisible4Edit=true;
                  /*  axios.get("/checkgroup/findById.do?id="+row.id).then((res)=>{
                        if(res.data.flag){
                            this.formData=res.data.data;
                            this.$message.success(res.data.message);

                        }else {
                            this.$message.error(res.data.message);
                        }
                    });*/
                  /*  axios.get("/checkitem/findAll.do").then((res)=>{
                        this.tableData=res.data.data;*/
                  /*优化：  把三条请求合成一条，以此来提高性能*/
                        axios.get("/checkgroup/findByIdSelectCheckItem.do?id="+row.id).then((res)=>{
                            if(res.data.flag){
                                this.tableData=res.data.data.items;
                                this.checkitemIds=res.data.data.ids;
                                this.formData=res.data.data.info;
                            }else {
                                this.$message.error(res.data.message);
                            }
                        })
                   /* })*/

                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage=currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    axios.post("/checkgroup/deleteById.do",row).then((res)=>{
                        if(res.data.flag){
                            this.$message.success(res.data.message);
                            this.findPage();
                        }else {
                            this.$message.error(res.data.message)
                        }
                    })
                }
            }
        })
    </script>
</html>
